export default class MessageQueue {
  constructor(options) {
    this.options = options
    this.queue = []
    this.running = false
  }

  push(item) {
    this.queue.push(item)
    this.run()
  }

  run() {
    if (this.running) return
    if (this.queue.length <= 0) return

    this.options.onRun(this.queue.shift())
  }

  next() {
    this.running = false
    this.run()
  }
}
